package com.ssmp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssmp.dao.BookDao;
import com.ssmp.domain.Book;
import com.ssmp.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author newThread
 * @className BookServiceImpl
 * @date 2022/2/4 23:37
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;
    @Override
    public Boolean addBook(Book book) {
        int insert = bookDao.insert(book);
        return insert>0;
    }

    @Override
    public Boolean delBook(Integer id) {
        int delete = bookDao.deleteById(id);
        return delete>0;
    }

    @Override
    public Boolean updateBook(Book book) {
        int update = bookDao.updateById(book);
        return update>0;
    }

    @Override
    public Book queryBookById(Integer id) {
        return bookDao.selectById(id);
    }

    @Override
    public List<Book> queryAllBook() {
        return bookDao.selectList(null);
    }

    @Override
    public IPage<Book> getPage(int current, int size) {
        Page<Book> bookPage = new Page<>();
        System.out.println(bookPage.getCurrent());
        System.out.println(bookPage.getSize());
        System.out.println(bookDao.selectList(null));
        return bookPage;
    }
}
